<?php

namespace Common\Model;

use Think\Model;

/*
 * 手机模型表
 */

class PhoneMoModel extends Model {

    protected $_auto = array(/* array(完成字段1,完成规则,[完成条件,附加规则]) */
        array('addTime', 'time', 1, 'function'),
        array('updateTime', 'time', 2, 'function'),
        array('isOn', '1', 1),
    );  // 自动完成定义
	
    /*
     * 获取一条品牌信息
    */
    public function getPhoneModel($id,$where=array(),$field = "*"){
    	$where['modelID']=$id;
    	$rt = $this->field($field)->where($where)->find();
    	return $rt;
    }
    
    /*
     * 获取手机机型列表
    */
    public function getPhoneModelList($pageNo = 1, $pageSize = 15, $where = array(), $order = array(), $field = "*") {
        $rt = $this->field($field)->where($where)->page("$pageNo,$pageSize")->order($order)->select();
        return $rt;
    }
	
    /*
     * 获取手机机型总数
    */
    public function getPhoneListLength($where = array()) {
        $result = $this->where($where)->count();
        return $result;
    }

    /*
     * 添加
     */
	public function addModel($data = '') {
        $rt = false;
        if ($this->create($data)) {
            $rt = $this->add();
        }
        return $rt;
    }

    /*
     * 更新
     */

    public function updateModel($data = '') {
        $rt = false;
        if ($this->create($data)) {
            $rt = $this->save();
        }
        return $rt;
    }

    /*
     * 编辑
     */

    public function editModel($modelID) {
        $model = $this->where("modelID = $modelID")->find();  //，find()返回一个一维数组，select()返回一个二维数组
        return $model;          //返回一维数组
    }

    /*
     * 移除，只是隐藏，并非真的从数据库中删除数据
     */

    public function deleteModel($modelID) {
        $data['isOn'] = 0;
        $data['modelID'] = $modelID;
        $model = $this->save($data);
        return $model;          //成功返回一个真值
    }
    
     /*获取品牌ID*/
    public function getBrandID($modelID){
       $brandID = $this->where("modelID = $modelID")->getField('brandID');
       return $brandID;
    } 

    /*获得总分*/
    public function getPrice($modelID){
        $price = $this->where("modelID = $modelID")->getField('price');
        return $$price;
    }
        
 
}
